﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;


namespace advadev.Windows.Graph
{

    /// <summary>
    /// Represents a layer element border
    /// </summary>
    internal class LayerElementBorder : Border
    {

        #region dependency properties
        static internal readonly DependencyProperty GraphSegmentProperty = DependencyProperty.Register("GraphSegment", typeof(GraphSegment), typeof(LayerElementBorder), new UIPropertyMetadata(null));
        internal GraphSegment GraphSegment
        {
            get { return (GraphSegment)GetValue(GraphSegmentProperty); }
            set { SetValue(GraphSegmentProperty, value); }
        }
        #endregion dependency properties


        /// <summary>
        /// Executes the hit test
        /// </summary>
        /// <param name="hitTestParameters">
        /// Hit test parameters
        /// </param>
        /// <returns>
        /// Hit test result
        /// </returns>
        override protected HitTestResult HitTestCore(PointHitTestParameters hitTestParameters)
        {
            if (GraphSegment != null)
            {
                LayerElementContainer container = DataContext as LayerElementContainer;
                if (container != null)
                {
                    Visual visual = container.LayerElement as Visual;
                    if (visual != null)
                    {
                        HitTestResult result = VisualTreeHelper.HitTest(visual, hitTestParameters.HitPoint);
                        if (result != null)
                        {
                            GraphSegment.LayerElementHit = true;
                        }
                        else
                        {
                            GraphSegment.LayerElementHit = false;
                        }
                    }
                }
            }
            return null;
        }

    }

}
